package com.kizitonwose.calendarview;

import com.kizitonwose.calendarview.fraction.BaseFraction;
import com.kizitonwose.calendarview.slice.MainAbilitySlice;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.content.Intent;
import ohos.multimodalinput.event.KeyEvent;

public class MainAbility extends FractionAbility {
    private BaseFraction currentFaction;
    private MainAbilitySlice currentAbilitySlice;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName());
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
        if (currentFaction != null && keyCode == KeyEvent.KEY_BACK) {
            //执行的是弹出栈操作，弹出后需重新入栈（对应add方法）
            getFractionManager().popFromStack();
            currentFaction = null;
            currentAbilitySlice.setCurrentFaction(null);
            return true;
        }
        return super.onKeyUp(keyCode, keyEvent);
    }

    public void setCurrentFaction(BaseFraction currentFaction) {
        this.currentFaction = currentFaction;
    }

    public void setCurrentAbilitySlice(MainAbilitySlice currentAbilitySlice) {
        this.currentAbilitySlice = currentAbilitySlice;
    }

    public MainAbilitySlice getCurrentAbilitySlice() {
        return currentAbilitySlice;
    }
}
